package org.ediba.siri.web;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.ediba.siri.web.Builder;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;


public class TileController extends MultiActionController {
	
	public ModelAndView titleHandler(HttpServletRequest request, HttpServletResponse response, Object command){
		return new ModelAndView("title","title","SIRI");
	}

	public ModelAndView stylesHandler(HttpServletRequest request, HttpServletResponse response, Object command){
		List<String> _items = new ArrayList<String>(1);
		_items.add("style");
		return new ModelAndView("styles","items",_items);
	}
	
	public ModelAndView scriptsHandler(HttpServletRequest request, HttpServletResponse response, Object command){
		List<String> _items = new ArrayList<String>(1);
		_items.add("script");
		
		List<String> _roles = new ArrayList<String>(SecurityContextHolder.getContext().getAuthentication().getAuthorities().size());
		for (GrantedAuthority ga : SecurityContextHolder.getContext().getAuthentication().getAuthorities())
			_roles.add(ga.getAuthority());
		
		ModelAndView _mav = new ModelAndView("scripts");
		_mav.addObject("items", _items);
		_mav.addObject("roles", _roles);
		return _mav;
	}
	
	public ModelAndView topCenterHandler(HttpServletRequest request, HttpServletResponse response, Object command){
		ModelAndView mav = new ModelAndView("top_center");
		mav.addObject("items", Builder.topCenter());
		return mav;
	}
	
	public ModelAndView middleLeftHandler(HttpServletRequest request, HttpServletResponse response, Object command){
		return new ModelAndView("middle_left");
	}
	
	public ModelAndView middleCenterHandler(HttpServletRequest request, HttpServletResponse response, Object command){
		return new ModelAndView("middle_center");
	}
	
	public ModelAndView bottomCenterHandler(HttpServletRequest request, HttpServletResponse response, Object command){
		return new ModelAndView("bottom_center");
	}
}
